Skip to content

[0126] 优化 smart_font 字体加载性能#3361

Merged
da-liii merged 2 commits into
mainfrom
da/200_27/0126_smart_font_opt
May 19, 2026
Merged

[0126] 优化 smart_font 字体加载性能#3361
da-liii merged 2 commits into
mainfrom
da/200_27/0126_smart_font_opt

Conversation

@da-liii

@da-liii da-liii commented May 14, 2026

Copy link
Copy Markdown
Contributor

Summary

通过缓存避免 smart_font 字体加载过程中的重复函数调用:

  1. 添加 maybe_initialize_font:在 resolveresolve_rubber 中,避免对已初始化的子字体重复调用 initialize_font
  2. 缓存 family_tokens:在构造函数中缓存 trimmed_tokenize(family, ",") 结果,避免 resolve(string c)is_italic_prime 中重复分割字符串
  3. 缓存 given_font:在构造函数中缓存 logical_font 结果,避免 resolve(c, fam, attempt) 中重复计算
  4. 缓存 is_italic_prime 结果:避免对同一字体的斜体引号判断重复计算

Test plan

  • xmake r smart_font_test 全部通过(11 个测试用例)
  • 新增 test_performancetest_math_performance 回归测试覆盖大量字符解析场景

🤖 Generated with Claude Code

@da-liii da-liii force-pushed the da/200_27/0126_smart_font_opt branch from f6b589d to 7605d0c Compare May 15, 2026 02:13
da-liii and others added 2 commits May 15, 2026 12:17
通过缓存避免字体加载过程中的重复调用:
1. 添加 maybe_initialize_font,避免对已初始化子字体重复调用 initialize_font
2. 缓存 family tokenize 结果,避免 resolve 和 is_italic_prime 中重复分割字符串
3. 缓存 logical_font 结果,避免 resolve(c, fam, attempt) 中重复计算
4. 缓存 is_italic_prime 的结果

同时添加 test_performance 和 test_math_performance 回归测试。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@da-liii da-liii force-pushed the da/200_27/0126_smart_font_opt branch from 7605d0c to 341695f Compare May 15, 2026 05:34

@MoonL79 MoonL79 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@da-liii da-liii merged commit 0fed6ff into main May 19, 2026
5 checks passed
@da-liii da-liii deleted the da/200_27/0126_smart_font_opt branch May 19, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants